package com.jty.module_user.ui.fragment

import android.graphics.Color
import android.view.View
import android.widget.TextView
import com.alibaba.android.arouter.facade.annotation.Route
import com.czl.lib_base.config.AppConstants
import com.jty.lib_base.base.AppManager
import com.jty.lib_base.base.BaseFragment
import com.jty.lib_base.event.LiveBusCenter
import com.jty.module_user.BR
import com.jty.module_user.R
import com.jty.module_user.databinding.UserFragmentSetBinding
import com.jty.module_user.viewmodel.SetViewModel
import com.kongzue.dialogx.dialogs.CustomDialog
import com.kongzue.dialogx.interfaces.OnBindView

@Route(path = AppConstants.Router.User.F_SET)
class UserSetFragment : BaseFragment<UserFragmentSetBinding, SetViewModel>() {

    override fun initContentView(): Int {
        return R.layout.user_fragment_set
    }

    override fun initVariableId(): Int {
        return BR.viewModel
    }

    override fun initViewObservable() {
        super.initViewObservable()

        viewModel.uc.onClickOutLogin.observe(this){
            val customDialog: CustomDialog = CustomDialog.build()
                .setEnterAnimDuration(0)
                .setExitAnimDuration(0)
                .setMaskColor(Color.parseColor("#4D000000"))
                .setCustomView(object : OnBindView<CustomDialog?>(R.layout.base_dialog_outlogin) {
                    override fun onBind(dialog: CustomDialog?, v: View) {
                        val tv_ok = v.findViewById<TextView>(R.id.tv_ok) as TextView
                        tv_ok.setOnClickListener {

                            viewModel.model.outLoginReset()
                            dialog?.dismiss()
                            LiveBusCenter.postLogoutEvent(3)
                            startContainerActivity(AppConstants.Router.Login.F_LOGIN)
                            AppManager.instance.finishAllActivity();
                        }

                        val tv_cancel = v.findViewById<TextView>(R.id.tv_cancel) as TextView
                        tv_cancel.setOnClickListener {
                            dialog?.dismiss()
                            LiveBusCenter.postLogoutEvent(2)
                        }
                    }
                })
            customDialog.show()
            LiveBusCenter.postLogoutEvent(1)



        }
    }
}